import javax.xml.transform.Result;
import java.sql.*;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ReservationBean {

//    连接数据库
    public java.sql.Connection getH2Connection(String url, String username, String password) throws SQLException {
        Connection connection = null;
        try {
            Class.forName("org.h2.Driver");
            connection =  DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return connection;
    }

//    从预约表中查询
    public ResultSet getResultSetFromRservations(String tno) throws SQLException {
        ResultSet resultSet = null;
        java.sql.Connection connection = getH2Connection("jdbc:h2:file:d:/temp/h2/teaching","sa","");


        if(connection == null){
            return null;
        }
        else{
            String sql = "SELECT * FROM reservations WHERE tno = '"+tno+"'";
            Statement statement = connection.createStatement();
            resultSet = statement.executeQuery(sql);
            while(resultSet.next()){
                System.out.println(resultSet.getString(1)
                        + " "+resultSet.getString(2)
                        +" "+resultSet.getString(3)
                        +" "+resultSet.getString(4)
                        +" "+resultSet.getString(5));//connection1 = getH2Connection("jdbc:h2:file:d:/temp/h2/teaching","sa","");
            }

        }
        return resultSet;
    }

}
